<?xml version="1.0" encoding="utf-8"?>
<!--
                                                                                     
 h       t     t                ::       /     /                     t             / 
 h       t     t                ::      //    //                     t            // 
 h     ttttt ttttt ppppp sssss         //    //  y   y       sssss ttttt         //  
 hhhh    t     t   p   p s            //    //   y   y       s       t          //   
 h  hh   t     t   ppppp sssss       //    //    yyyyy       sssss   t         //    
 h   h   t     t   p         s  ::   /     /         y  ..       s   t    ..   /     
 h   h   t     t   p     sssss  ::   /     /     yyyyy  ..   sssss   t    ..   /     
                                                                                     
	<https://y.st./>
	Copyright © 2017 Alex Yst <mailto:copyright@y.st>

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program. If not, see <https://www.gnu.org./licenses/>.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="https://y.st./en/weblog/2017/07-July/14.xhtml" />
		<title>Mood swings and maths &lt;https://y.st./en/weblog/2017/07-July/14.xhtml&gt;</title>
		<link rel="icon" type="image/png" href="/link/CC_BY-SA_4.0/y.st./icon.png" />
		<link rel="stylesheet" type="text/css" href="/link/basic.css" />
		<link rel="stylesheet" type="text/css" href="/link/site-specific.css" />
		<script type="text/javascript" src="/script/javascript.js" />
		<meta name="viewport" content="width=device-width" />
	</head>
	<body>
		<nav>
			<p>
				<a href="/en/">Home</a> |
				<a href="/en/a/about.xhtml">About</a> |
				<a href="/en/a/contact.xhtml">Contact</a> |
				<a href="/a/canary.txt">Canary</a> |
				<a href="/en/URI_research/"><abbr title="Uniform Resource Identifier">URI</abbr> research</a> |
				<a href="/en/opinion/">Opinions</a> |
				<a href="/en/coursework/">Coursework</a> |
				<a href="/en/law/">Law</a> |
				<a href="/en/a/links.xhtml">Links</a> |
				<a href="/en/weblog/2017/07-July/14.xhtml.asc">{this page}.asc</a>
			</p>
			<hr/>
			<p>
				Weblog index:
				<a href="/en/weblog/"><abbr title="American Standard Code for Information Interchange">ASCII</abbr> calendars</a> |
				<a href="/en/weblog/index_ol_ascending.xhtml">Ascending list</a> |
				<a href="/en/weblog/index_ol_descending.xhtml">Descending list</a>
			</p>
			<hr/>
			<p>
				Jump to entry:
				<a href="/en/weblog/2015/03-March/07.xhtml">&lt;&lt;First</a>
				<a rel="prev" href="/en/weblog/2017/07-July/13.xhtml">&lt;Previous</a>
				<a rel="next" href="/en/weblog/2017/07-July/15.xhtml">Next&gt;</a>
				<a href="/en/weblog/latest.xhtml">Latest&gt;&gt;</a>
			</p>
			<hr/>
		</nav>
		<header>
			<h1>Mood swings and maths</h1>
			<p>Day 00860: Friday, 2017 July 14</p>
		</header>
<section id="general">
	<h2>General news</h2>
	<p>
		...
	</p>
	<p>
		My <a href="/a/canary.txt">canary</a> still sings the tune of freedom and transparency.
	</p>
</section>
<section id="dreams">
	<h2>Dream journal</h2>
	<p>
		I dreamed I, along with several other people, was captured by some cruel and viscous criminals.
		I complied with everything they asked for and didn&apos;t make any attempts to escape.
		They still put my left hand in a device that looked very much like an old paper cutter, and chopped off my thumb.
		Strangely, while that did hurt like hell, I feel like it wasn&apos;t the worst pain I&apos;ve experienced in dreams before.
		Even after they took my thumb, I didn&apos;t resist them, as there wasn&apos;t a way for me to safely escape.
		However, they next decided to aim for my teeth.
		They stuck some pliers in my mouth and started tapping around to find the one they wanted to take first.
		In the real world, several of my teeth are broken, and in the dream, those same teeth were broken in the same ways.
		This is the first time I can ever remember noticing my broken teeth in a dream.
		In any case, as they were about to pull one of my more-broken ones, I realised somehow that it was a dream at the last minute.
		Now that I had a way out, I wasn&apos;t going to stay there any longer, and I forced myself to wake up.
		Even the extreme pain of having a thumb cut off didn&apos;t wake me, but waking myself up once I knew I was dreaming wasn&apos;t hard at all.
	</p>
</section>
<section id="mental">
	<h2>Mental health watch</h2>
	<p>
		I thought I was over this, but I had a severe, downward mood swing again today.
		It was nowhere near as bad as that time recently that caused me to want to die for a bit, but it certainly wasn&apos;t pleasant.
		Once I was at work though, I seemed to recover fairly quickly.
		It took me a bit to realise why, but I think it was my work at the register!
		I have this thing I do when I&apos;m on a till: I add up the price of each customer&apos;s order in my head, instead of punching it into the register before telling the customer the price of what they want.
		It helps prevent paperwork caused by customers changing their minds (we can&apos;t void items from an order), but mostly, it&apos;s just a simple brain exercise I enjoy.
		The work there is so mindless that I have to keep myself entertained, right?
		I might as well do it in a productive way.
		Anyway, I think I&apos;ve discovered the key to fighting off these mood swings.
		I need to exercise my logical capabilities.
		When I have a downward mood swing, it feels like my logical side is succumbing to my emotional side, so I just need to do some maths or programming to coerce my logical side back into temporary dominance.
		Being a programmer puts me in a uniquely useful position for this.
		Most peopl eprobably have less logic puzzles to work on, but when programming, the logic puzzles are endless.
		I could go on forever programming and solving problems if there was enough time.
		Hopefully this time, it&apos;s a real solution.
		The stupid handedness thing isn&apos;t as effective as I&apos;d hoped, but it&apos;s also probably not needed.
		I can go back to using whatever hand I feel like with one exception as far as tasks: writing.
		I think pumping language through the incorrect hand has been damaging my intellectual capacity, and I need to recover from that.
		Learning to use both hands is one thing, but people should probably stick with their naturally-good hand for writing with.
		One of my coworkers also suggested I try using chocolate.
		Supposedly, chocolate helps level out one&apos;s moods as well.
	</p>
</section>
<section id="university">
	<h2>University life</h2>
	<p>
		I wrote up my initial discussion post for the week:
	</p>
	<blockquote>
		<p>
			The first thing to consider when choosing which collection type to use is the most important.
			What do we want to use the collection for?
			Are we using it as a key/value store, or are we storing only values?
			If we&apos;re storing keys and values, we&apos;re going to want a map type of some sort.
			If we&apos;re storing only values, do we want duplicates preserved?
			If we want duplicates to be preserved, we shouldn&apos;t be using a set collection type.
			However, if preserving duplicates would be unwanted for our usage, a list collection type would be a bad idea.
			Efficiency is important, but not as important as functionality.
			We need to choose which sub-interface of <code>Collection</code> is has what we&apos;re looking for: <code>Set</code> or <code>List</code>.
		</p>
		<h3><code>List</code></h3>
		<p>
			If you decide that you want duplicate entries preserved, it&apos;s time to choose between a <code>LinkedList</code> and an <code>ArrayList</code>.
			If you think you&apos;ll need to add items to the beginning or middle of the list, a linked list is the better option.
			Items can be added to arbitrary locations in the list without any major overhead.
			When dealing with arrays, insertions and deletions anywhere but at the end of the array require copying all elements that are in the list after the item to be added or removed to a new location.
			Linked lists don&apos;t suffer from this weakness.
			Arrays show their strength when you instead need to arbitrarily access values.
			Random access (accessing the values out of order) is much faster and more efficient with array lists than with linked lists.
		</p>
		<p>
			The <code>LinkedList</code> class also has some class-specific methods not provided by the <code>List</code> interface.
			If you plan to use your list as a queue or stack, the added methods of <code>LinkedList</code> could make that class a better fit for you than <code>ArrayList</code>.
			Due to the way in which linked lists work, they&apos;re probably a better choice for the building of queues and stacks too, so again, you might choose a linked list for that.
			Arrays function okay as stacks sometimes, but they don&apos;t make good queue structures.
		</p>
		<h3><code>Set</code></h3>
		<p>
			If you decide you want to know which elements are in your collection, but there&apos;s no need to keep multiple copies of each item if more than one exist, you probably want a set.
			Now, you need to look at whether a <code>TreeSet</code> of a <code>HashSet</code> is the right option for your use case.
			If you need your set items to always be in order, a tree set is the right data type for you.
			It keeps everything organised in an efficient manner.
			If order doesn&apos;t matter though, a hash set provides better efficiency.
			In a tree, you may have to visit a few items before finding the right one, or finding if the right one is even present in the tree.
			In a hash set though, the correct item can always be visited the first time.
			The disadvantage though is that the order of the items is completely arbitrary, and no useful order can be set.
		</p>
		<p>
			(There&apos;s also the case of the <code>EnumSet</code> class.
			An <code>enum</code> class is itself sort of like a set, but sometimes, you need a subset.
			In this case, an actual set object could be useful.
			Enums are so simple that Java is able to cut out a lot of the overhead that applies to most classes, but not <code>enum</code> classes.
			If you need a set of objects from an <code>enum</code> class, your set should probably be of the <code>EnumSet</code> class for efficiency.
			This class uses an efficient bit vector to keep track of which objects are and are not in the set, which is something not possible when an unlimited number of possibilities are available for a given type.)
		</p>
		<h3><code>Map</code></h3>
		<p>
			If you decide you need a key/value store, you&apos;re going to want a map.
			The Java language doesn&apos;t have associative arrays, at least not as a basic data type provided by the language, but maps provide a similar feature as a class of objects.
			In most cases, you should probably use an object of class <code>HashMap</code>.
			This class uses an efficient mechanism for storing key/value pairs that involves hashing the key and using that hash to know where the value should be placed in memory or where the value has already been placed.
			However, a <code>TreeMap</code> does have advantages in some cases.
			A <code>TreeMap</code> keeps all the keys organised, so they&apos;re all in a predictable order.
			It&apos;s worth noting though that, strictly-speaking, maps aren&apos;t considered to be collections.
			As such, they don&apos;t implement the <code>Collection</code> interface.
			Like a list, they hold an arbitrary number of values, but variable types won&apos;t match for methods that require a collection as input.
		</p>
	</blockquote>
</section>
		<hr/>
		<p>
			Copyright © 2017 Alex Yst;
			You may modify and/or redistribute this document under the terms of the <a rel="license" href="/license/gpl-3.0-standalone.xhtml"><abbr title="GNU&apos;s Not Unix">GNU</abbr> <abbr title="General Public License version Three or later">GPLv3+</abbr></a>.
			If for some reason you would prefer to modify and/or distribute this document under other free copyleft terms, please ask me via email.
			My address is in the source comments near the top of this document.
			This license also applies to embedded content such as images.
			For more information on that, see <a href="/en/a/licensing.xhtml">licensing</a>.
		</p>
		<p>
			<abbr title="World Wide Web Consortium">W3C</abbr> standards are important.
			This document conforms to the <a href="https://validator.w3.org./nu/?doc=https%3A%2F%2Fy.st.%2Fen%2Fweblog%2F2017%2F07-July%2F14.xhtml"><abbr title="Extensible Hypertext Markup Language">XHTML</abbr> 5.1</a> specification and uses style sheets that conform to the <a href="http://jigsaw.w3.org./css-validator/validator?uri=https%3A%2F%2Fy.st.%2Fen%2Fweblog%2F2017%2F07-July%2F14.xhtml"><abbr title="Cascading Style Sheets">CSS</abbr>3</a> specification.
		</p>
	</body>
</html>

